<template>
  <view>
    <view style="background-image: url('https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangGroup-1228.png'); background-size: cover; background-repeat: no-repeat;">
      <image class="header-image" :src="imageUrl + '/liuyanqiang/liuyanqiangFrame-1328.png'"></image>
      <view class="srk">
        <view class="toxiang">
          <image :src="imageUrl + '/liuyanqiang/liuyanqiangimage-49646.png'" style="width: 60.7rpx;height: 60.7rpx;"></image>
        </view>
        <input
          v-model="inputValue"
          class="my-input"
          type="text"
          placeholder="快来留言吧，留下你的独特印记!"
          @confirm="addMessage"
        />
        <view class="sxtb" @click="toggleSignature">
          <image :src="imageUrl + '/liuyanqiang/liuyanqiangGroup-1037.png'" style="width: 40.54rpx;height: 40.54rpx;padding-left: 10px;"></image>
          <span class="wz1">手写签名</span>
        </view>
      </view>
      <scroll-view scroll-x="true" class="scroll-container">
        <view class="scroll-item">
          <view class="item-content-left">
            <view class="messages-containers">
              <view v-for="(message, index) in leftMessages" :key="index" :class="containerClasses[index]" class="single-message-container">
                <span v-if="!isImageMessage(message, true)">{{ message.text }}</span>
                <image v-if="isImageMessage(message, true)" :src="message.imagePath || message.text" class="message-image"></image>
              </view>
            </view>
          </view>
        </view>
        <view class="scroll-item" v-if="rightMessages.length > 0">
          <view class="item-content-right">
            <view class="messages-containers">
              <view v-for="(message, index) in rightMessages" :key="index" :class="containerClasses[index]" class="single-message-container">
                <span v-if="!isImageMessage(message, false)">{{ message.text }}</span>
                <image v-if="isImageMessage(message, false)" :src="message.imagePath || message.text" class="message-image"></image>
              </view>
            </view>
          </view>
        </view>
      </scroll-view>
      <view v-if="showSignature" class="shoxie">
		<text class="shouxie-biaoti">手写留言</text>  
        <view class="close-button" @click="toggleSignature">×</view>
        <view class="sxb">
          <l-signature disableScroll ref="signatureRef" :penColor="penColor" :penSize="penSize" :maxLineWidth="20" :openSmooth="openSmooth" type></l-signature>
        </view>
        <view class="sxb-anniu">
          <button class="anniu-sxb" @click="onClick('clear')"> <p class="sxb-wenzi">清空</p> </button>
          <button class="anniu-sxb2" @click="onClick('save')"> <p class="sxb-wenzi">保存</p> </button>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
	export default {
	  data() {
	    return {
		imageUrl: this.$imageUrl,	
		leftMessages: [],
		rightMessages: [],
		        touchStartX: 0,
		        touchStartY: 0,
		        startY: 0,
		        isTouching: false,
		        inputValue: '',
		        title: 'Hello',
		        penColor: 'black',
		        penSize: 5,
		        url: '',
		        openSmooth: true,
		        showSignature: false,
		        containerClasses: Array.from({ length: 13 }, (_, index) => `message-container-${index}`),
		        isNewMessage: false,
	      scrollItems: [
	        { id: 1, text: '项目 1 内容' },
	        { id: 2, text: '项目 2 内容' },
	      ],
	    };
	  },
	    methods: {
	      onClick(type) {
	        if (type === 'openSmooth') {
	          this.openSmooth =!this.openSmooth;
	          return;
	        }
	         if (type === 'save') {
	             this.$refs.signatureRef.canvasToTempFilePath({
	               success: (res) => {
	                 console.log('临时文件路径：', res.tempFilePath);
	                 const newMessage = {
	                   id: Date.now(),
	                   text: `手写签名：${res.tempFilePath}`,
	                   imagePath: res.tempFilePath, // 添加图片路径属性
	                   isNew: true, // 设置标志位为新留言
	                 };
	                 // 判断添加到左边还是右边
	                 if (this.leftMessages.length < 13) {
	                   this.leftMessages.push(newMessage);
	                 } else if (this.rightMessages.length < 13) {
	                   this.rightMessages.push(newMessage);
	                 } else {
	                   // 如果两边都满了13条，从左边开始覆盖旧留言
	                   this.leftMessages.shift();
	                   this.leftMessages.push(newMessage);
	                 }
	                 this.currentImagePath = res.tempFilePath;
	                 this.isNewMessage = true; // 设置全局标志位为新留言
					 this.toggleSignature();
	               },
	             });
	             return;
	           }
			   if (this.$refs.signatureRef)
			   	this.$refs.signatureRef[type]()
			   },
	      addMessage(event) {
	        let value = event && event.detail && event.detail.value? event.detail.value : '';
	        if (value.trim()!== '') {
	          const newMessage = {
	            id: Date.now(),
	            text: value,
	          };
	          if (this.leftMessages.length < 13) {
	            this.leftMessages.push(newMessage);
	          } else if (this.rightMessages.length < 13) {
	            this.rightMessages.push(newMessage);
	          } else {
	            // 如果两边都满了13条，从左边开始覆盖旧留言
	            this.leftMessages.shift();
	            this.leftMessages.push(newMessage);
	          }
	          this.inputValue = '';
	        }
	      },
	      toggleSignature() {
	        this.showSignature =!this.showSignature;
	      },
	     isImageMessage(message, isLeft) {
	       return isLeft?
	         this.leftMessages.some(leftMsg => leftMsg.id === message.id && leftMsg.text.startsWith('手写签名：')) :
	         this.rightMessages.some(rightMsg => rightMsg.id === message.id && rightMsg.text.startsWith('手写签名：'));
	     },
	    },
	    mounted() {
	      setTimeout(() => {
	        if (this.$refs.myInput) {
	          this.$refs.myInput.focus();
	        }
	      }, 200);
	    },
	  };
	  </script>

<style scoped>
	.sxb-wenzi{
		width: 30px;
		height: 15px;
		color: #808D84;
		font-size: 14px;
		font-weight: bold;
		margin-top: 0.4vh;
		margin-left: 11vw;
		/* border: 2px solid blue; */
	}
	.anniu-sxb{
		width: 150px;
		height: 41px;
		background: rgba(128,141,132,0.2);
		border-radius: 70px 70px 70px 70px;
		margin-left: 10vw;
	}
	.anniu-sxb2{
		width: 150px;
		height: 41px;
		background: rgba(128,141,132,0.2);
		border-radius: 70px 70px 70px 70px;
		margin-right: 10vw;
	}
	.shouxie-biaoti{
		font-weight: bold;
		font-size: 18px;
		color: #808D84;
		margin-top: 1.5vh;
		margin-left: 40vw;
		
	}
	.scroll-container {
	  white-space: nowrap;
	  width: 100vw;
	  height: 100vh;
	}
	.scroll-item {
	  display: inline-block;
	  width: 100%;
	  height: 100%;
	}
	.scroll-container-image{
		width: 100vw;
		height: 100vh;
	}
	.item-content-left {
	  position: relative;
	  height: 100vh;
	}
	.item-content-right {
	   position: relative;
	   height: 100vh;
	}
	.fanhuijianto{
	  position: absolute;
	  z-index: 4;
	  width: 40rpx;
	  height: 40rpx;
	  background-color: #fff;
	  margin-left: 5%;
	  margin-top: 14%;
	}
	.header-image {
	  position: absolute;
	  width: 298rpx;
	  height: 154rpx;
	  margin-top: 142rpx;
	  margin-left: 226rpx;
	  z-index: 1;
	}
	.srk{
	position: absolute;
	z-index: 2;
	display: flex;
	position: absolute;
	margin-top: 85vh;
	width: 100%;
	height: auto;
	}
	.toxiang{
	z-index: 2;
	width: auto;
	height: auto;
	margin-top: 12%;
	margin-left: 50rpx;
	}
	.my-input {
	z-index: 2;
	width: 450rpx;
	height: 60rpx;
	margin-top: 90rpx;
	margin-left: 15rpx;
	padding-left: 30rpx;
	background: #E4EBE9;
	border-radius: 100rpx;
	font-size: 24rpx;
	color: black;
	background-image: url('https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangGroup-1035.png');
	background-repeat: no-repeat;
	 background-position: right 30rpx center;
	}
	.sxtb{
	z-index: 2;
	display: flex;
	flex-direction: column;
	width: 100rpx;
	height: 65rpx;
	float: right;
	margin-top: 12%;
	margin-left: 20rpx;
	}
	.wz1{
	width: 96rpx;
	height: 36rpx;
	font-family: Source Han Sans CN, Source Han Sans CN;
	font-weight: 400;
	font-size: 24rpx;
	color: #FFFFFF;
	line-height: 28rpx;
	text-align: left;
	font-style: normal;
	text-transform: none;
	}
	.shoxie{
	z-index: 4;
	position: absolute;
	display: flex;
	flex-direction: column;
	top: 55vh;
	width: 100%;
	height: 45%;
	background-color: #F1F2F2;
	border-radius: 5%;
	}
	.close-button {
	position: absolute;
	  top: 0.5vh;
	  right: 9vw;
	  padding: 10rpx;
	  font-size: 24px;
	  color: #808D84;
	  transform:scale(1.2);
	}
	.sxb{
		width: 80%;
		height: 500rpx;
		background-color: #F1F2F2;
		border: 2px solid #fff;
		margin-left: 9.5vw;
		margin-top: 4%;
		border-radius: 10%;
	}
	.sxb-anniu{
		display: flex;
		margin-top: 1vh;
	}
	.messages-containers{
		position: absolute;
		width: 100%;
		height: 60vh;
		margin-top: 20vh;
	}
	.message-image {
	  position: absolute;
	  padding-left: 20rpx;
	  padding-top: 14rpx;
	  width: 80%;
	  height: 80%;
	}
.message-container-0 {
  position: relative;
  z-index: 4;
  position: absolute;
  width: 217.49rpx;
  height: 217.49rpx;
  margin-left: 36rpx;
  background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49649.png);
}
.message-container-0 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-1 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 204.03rpx;
   height: 204.03rpx;
   margin-left: 40%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49651.png);
}
.message-container-1 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-2 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 220.5rpx;
   height: 220.5rpx;
   margin-left: 72%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49653.png);
}
.message-container-2 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-3 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 246.04rpx;
   height: 483.85rpx;
   margin-top: 10vh;
   margin-left: 36rpx;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49652.png);
}
.message-container-3 span {
  position: absolute;
  width: 146rpx;
  height: 180rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 90px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-4 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 208.6rpx;
   height: 208.6rpx;
   margin-top: 10vh;
   margin-left: 40%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49651.png);
}
.message-container-4 span {
  position: absolute;
  width: 96rpx;
  height: 72rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-5 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 208.6rpx;
   height: 208.6rpx;
   margin-top: 20vh;
   margin-left: 40%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49649.png);
}
.message-container-5 span {
  position: absolute;
  width: 96rpx;
  height: 72rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-6 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 208.6rpx;
   height: 208.6rpx;
   margin-top: 10vh;
   margin-left: 68%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49654.png);
}
.message-container-6 span {
  position: absolute;
  width: 96rpx;
  height: 72rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 35px;
  top: 44px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-7 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 208.6rpx;
   height: 208.6rpx;
   margin-top: 25vh;
   margin-left: 70%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49649.png);
}
.message-container-7 span {
  position: absolute;
  width: 96rpx;
  height: 72rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-8 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 204.03rpx;
   height: 204.03rpx;
   margin-top: 40vh;
   margin-left: 36rpx;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49651.png);
}
.message-container-8 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-9 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 220.5rpx;
   height: 220.5rpx;
   margin-top: 55vh;
   margin-left: 36rpx;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49653.png);
}
.message-container-9 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-10 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 246.04rpx;
   height: 483.85rpx;
   margin-top: 30vh;
   margin-left: 70%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49652.png);
  transform: rotate(-90deg);
}
.message-container-10 span {
  position: absolute;
  width: 146rpx;
  height: 180rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 10px;
  top: 40px;
  transform: rotate(90deg);
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-11 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 204.03rpx;
   height: 204.03rpx;
   margin-top: 55vh;
   margin-left: 40%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49651.png);
}
.message-container-11 span {
  position: absolute;
  width: 120rpx;
  height: 108rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 25px;
  top: 30px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
.message-container-12 {
   position: relative;
   z-index: 4;
   position: absolute;
   width: 208.6rpx;
   height: 208.6rpx;
   margin-top: 55vh;
   margin-left: 68%;
   background-image: url(https://xnlv.lizxx.com/image/xnlv/static/liuyanqiang/liuyanqiangimage-49654.png);
}
.message-container-12 span {
  position: absolute;
  width: 96rpx;
  height: 72rpx;
  font-size: 24rpx;
  font-family: Source Han Sans CN-Regular;
  color: black;
  left: 35px;
  top: 44px;
  white-space: normal; /* 允许换行 */
  word-wrap: break-word; /* 当单词过长时进行换行 */
  overflow: auto;
}
</style>
